home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / ddx / mfb / RCS / mfbcmap.c,v < prev    next >
Encoding:
Text File  |  1990-02-15  |  5.4 KB  |  203 lines

  1. head     1.1;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.1
  10. date     90.02.14.19.57.59;  author tve;  state Exp;
  11. branches ;
  12. next     ;
  13.  
  14.  
  15. desc
  16. @Original X11R4 distribution
  17. @
  18.  
  19.  
  20.  
  21. 1.1
  22. log
  23. @Initial revision
  24. @
  25. text
  26. @/***********************************************************
  27. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  28. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  29.  
  30.                         All Rights Reserved
  31.  
  32. Permission to use, copy, modify, and distribute this software and its 
  33. documentation for any purpose and without fee is hereby granted, 
  34. provided that the above copyright notice appear in all copies and that
  35. both that copyright notice and this permission notice appear in 
  36. supporting documentation, and that the names of Digital or MIT not be
  37. used in advertising or publicity pertaining to distribution of the
  38. software without specific, written prior permission.  
  39.  
  40. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  41. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  42. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  43. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  44. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  45. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  46. SOFTWARE.
  47.  
  48. ******************************************************************/
  49. /* $XConsortium: mfbcmap.c,v 5.3 89/07/19 15:48:00 rws Exp $ */
  50. #include "X.h"
  51. #include "scrnintstr.h"
  52. #include "colormapst.h"
  53. #include "resource.h"
  54.  
  55. extern int    TellLostMap(), TellGainedMap();
  56. /* A monochrome frame buffer is a static gray colormap with two entries.
  57.  * We have a "required list" of length 1.  Because we can only support 1
  58.  * colormap, we never have to change it, but we may have to change the 
  59.  * name we call it.  If someone installs a new colormap, we know it must
  60.  * look just like the old one (because we've checked in dispatch that it was
  61.  * a valid colormap identifier, and all the colormap IDs for this device
  62.  * look the same).  Nevertheless, we still have to uninstall the old colormap
  63.  * and install the new one.  Similarly, if someone uninstalls a colormap,
  64.  * we have to install the default map, even though we know those two looked
  65.  * alike.  
  66.  * The required list concept is pretty much irrelevant when you can only
  67.  * have one map installed at a time.  
  68.  */
  69. static ColormapPtr InstalledMaps[MAXSCREENS];
  70.  
  71. int
  72. mfbListInstalledColormaps(pScreen, pmaps)
  73.     ScreenPtr    pScreen;
  74.     Colormap    *pmaps;
  75. {
  76.     /* By the time we are processing requests, we can guarantee that there
  77.      * is always a colormap installed */
  78.     *pmaps = InstalledMaps[pScreen->myNum]->mid;
  79.     return (1);
  80. }
  81.  
  82.  
  83. void
  84. mfbInstallColormap(pmap)
  85.     ColormapPtr    pmap;
  86. {
  87.     int index = pmap->pScreen->myNum;
  88.     ColormapPtr oldpmap = InstalledMaps[index];
  89.  
  90.     if(pmap != oldpmap)
  91.     {
  92.     /* Uninstall pInstalledMap. No hardware changes required, just
  93.      * notify all interested parties. */
  94.     if(oldpmap != (ColormapPtr)None)
  95.         WalkTree(pmap->pScreen, TellLostMap, (pointer)&oldpmap->mid);
  96.     /* Install pmap */
  97.     InstalledMaps[index] = pmap;
  98.     WalkTree(pmap->pScreen, TellGainedMap, (pointer)&pmap->mid);
  99.  
  100.     }
  101. }
  102.  
  103. void
  104. mfbUninstallColormap(pmap)
  105.     ColormapPtr    pmap;
  106. {
  107.     int index = pmap->pScreen->myNum;
  108.     ColormapPtr curpmap = InstalledMaps[index];
  109.  
  110.     if(pmap == curpmap)
  111.     {
  112.     if (pmap->mid != pmap->pScreen->defColormap)
  113.     {
  114.         curpmap = (ColormapPtr) LookupIDByType(pmap->pScreen->defColormap,
  115.                            RT_COLORMAP);
  116.         (*pmap->pScreen->InstallColormap)(curpmap);
  117.     }
  118.     }
  119. }
  120.  
  121. /*ARGSUSED*/
  122. void
  123. mfbResolveColor (pred, pgreen, pblue, pVisual)
  124.     unsigned short    *pred;
  125.     unsigned short    *pgreen;
  126.     unsigned short    *pblue;
  127.     VisualPtr        pVisual;
  128. {
  129.     /* 
  130.      * Gets intensity from RGB.  If intensity is >= half, pick white, else
  131.      * pick black.  This may well be more trouble than it's worth.
  132.      */
  133.     *pred = *pgreen = *pblue = 
  134.         (((30L * *pred +
  135.            59L * *pgreen +
  136.            11L * *pblue) >> 8) >= (((1<<8)-1)*50)) ? ~0 : 0;
  137. }
  138.  
  139. Bool
  140. mfbCreateColormap(pMap)
  141.     ColormapPtr    pMap;
  142. {
  143.     ScreenPtr    pScreen;
  144.     unsigned short  red0, green0, blue0;
  145.     unsigned short  red1, green1, blue1;
  146.     unsigned long   pix;
  147.     
  148.     pScreen = pMap->pScreen;
  149.     if (pScreen->whitePixel == 0)
  150.     {
  151.     red0 = green0 = blue0 = ~0;
  152.     red1 = green1 = blue1 = 0;
  153.     }
  154.     else
  155.     {
  156.     red0 = green0 = blue0 = 0;
  157.     red1 = green1 = blue1 = ~0;
  158.     }
  159.  
  160.     /* this is a monochrome colormap, it only has two entries, just fill
  161.      * them in by hand.  If it were a more complex static map, it would be
  162.      * worth writing a for loop or three to initialize it */
  163.  
  164.     /* this will be pixel 0 */
  165.     pix = 0;
  166.     if (AllocColor(pMap, &red0, &green0, &blue0, &pix, 0) != Success)
  167.     return FALSE;
  168.  
  169.     /* this will be pixel 1 */
  170.     if (AllocColor(pMap, &red1, &green1, &blue1, &pix, 0) != Success)
  171.     return FALSE;
  172.     return TRUE;
  173. }
  174.  
  175. /*ARGSUSED*/
  176. void
  177. mfbDestroyColormap (pMap)
  178.     ColormapPtr    pMap;
  179. {
  180.     return;
  181. }
  182.  
  183. Bool
  184. mfbCreateDefColormap (pScreen)
  185.     ScreenPtr    pScreen;
  186. {
  187.     VisualPtr    pVisual;
  188.     ColormapPtr    pColormap;
  189.     
  190.     for (pVisual = pScreen->visuals;
  191.      pVisual->vid != pScreen->rootVisual;
  192.      pVisual++)
  193.     ;
  194.     if (CreateColormap (pScreen->defColormap, pScreen, pVisual,
  195.             &pColormap, AllocNone, 0) != Success)
  196.     {
  197.     return FALSE;
  198.     }
  199.     (*pScreen->InstallColormap) (pColormap);
  200.     return TRUE;
  201. }
  202. @
  203.